import updateManager from './common/updateManager';
const AUTH = require('utils/auth')
App({
  onLaunch: function () {
    // 检测新版本
    const updateManager = wx.getUpdateManager()
    updateManager.onUpdateReady(function () {
      wx.showModal({
        confirmText: "确认更新",
        cancelText: "取消",
        content: "已有新的版本",
        success(res) {
          if (res.confirm) {
            updateManager.applyUpdate()
          }
        }
      })
    })
    /**
     * 初次加载判断网络情况
     * 无网络状态下根据实际情况进行调整
     */
    wx.getNetworkType({
      success(res) {
        const networkType = res.networkType
        if (networkType === 'none') {
          that.globalData.isConnected = false
          wx.showToast({
            title: "正在加载",
            icon: 'loading'
          })
        }
      }
    });

  },
  onShow: function () {
    updateManager();
    AUTH.login().then(isLogined => {
      console.log(isLogined)
      if (!isLogined) {
        AUTH.authorize()
      }
    })
  },
  globalData: {
    isLanding: true,
    userProfile: null
  }
});